package com.cloudsigns.factorymanager2.operate_maintain.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.customview.AddProductInforPoupWindow;
import com.cloudsigns.factorymanager2.project.customview.GeneralPurposePoupWindow;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

public class OperateMaintainQueryActivity extends BaseActivity implements ItemClickListener {
    private RelativeLayout rl_back;
    private TextView tv_title;

    private TextView edit_query_type, edit_airport_name;
    private View v_query_type, v_airport_name;
    private ImageView img_query_type, img_airport_name;
    private RelativeLayout rl_query;

    private GeneralPurposePoupWindow generalPurposePoupWindow;
    private String types[] = {"故障查询", "库存结存", "周期查询"};
    private AddProductInforPoupWindow addProductInforPoupWindow;
    private String airport_name[] = {""};

    private String clickType;

    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_operate_maintain_query);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);

        edit_query_type = findViewById(R.id.edit_query_type);
        v_query_type = findViewById(R.id.v_query_type);
        img_query_type = findViewById(R.id.img_query_type);
        edit_airport_name = findViewById(R.id.edit_airport_name);
        v_airport_name = findViewById(R.id.v_airport_name);
        img_airport_name = findViewById(R.id.img_airport_name);
        rl_query = findViewById(R.id.rl_query);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText(getResources().getString(R.string.query));
    }

    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);
        img_query_type.setOnClickListener(this);
        img_airport_name.setOnClickListener(this);
        rl_query.setOnClickListener(this);
    }

    // 查询类型
    private void showSearchTypesWindow(View anchor) {
        generalPurposePoupWindow = new GeneralPurposePoupWindow(this, types);
        generalPurposePoupWindow.setItemClick(this);
        generalPurposePoupWindow.showPopupWindow(anchor);
    }

    // 机场名称
    private void showSearchMonthsWindow(View anchor) {
        addProductInforPoupWindow = new AddProductInforPoupWindow(this, airport_name);
        addProductInforPoupWindow.setItemClick(this);
        addProductInforPoupWindow.showPopupWindow(anchor);
    }

    @Override
    public void widgetClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            // 查询类型
            case R.id.img_query_type:
                showSearchTypesWindow(v_query_type);
                clickType = "types";
                break;
            // 机场名称
            case R.id.img_query_month:
                showSearchMonthsWindow(v_airport_name);
                clickType = "month";
                break;
            // 查询
            case R.id.rl_query:
                break;
        }
    }

    @Override
    public void itemClick(View view, int position) {
        if ("types".equals(clickType)) {
            edit_query_type.setText(types[position]);
        } else if ("month".equals(clickType)) {
            edit_airport_name.setText(airport_name[position]);
        }
    }
}
